<?php
/********************
*    Stack Class    *
*  Coded by Moonbat *
*  October 5, 2008  *
********************/
class Stack {
	
	var $stack;
	
	public function __construct() {
		$this->stack = array();
	}
		
	public function is_empty() {
		if (empty($this->stack)) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	public function size() {
		return count($this->stack);
	}
	
	public function push($item) { // Shove an element on the stack
		if (array_push($this->stack, $item)) {
			return TRUE;
		} else {
			return FALSE;
		}
	}

	
	public function pop() { // Shoot off last item on the stack
		if (!$this->is_empty()) {
			array_pop($this->stack);
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	public function peek($position) { // Get certain element on the stack
		$elements = count($this->stack);
		if ($elements < $position) {
			unset($elements);
			return FALSE;
		} else {
			unset($elements);
			return $this->stack[$position];
		}
	}
	
	public function top(){
		return $this->stack[$this->size()-1];	
	}
	
	public function __destruct() {
		unset($this->stack);
	}
	
}
?>